import {login, getUserProfile} from '../../request/index'
Page({
    data: {
        
    },
    //options(Object)
    onLoad: function(options){
     
    },
    onReady: function(){
        
    },
    onShow: function(){
        
    },
    onHide: function(){

    },
    onUnload: function(){

    },
    onPullDownRefresh: function(){

    },
    onReachBottom: function(){

    },
    onShareAppMessage: function(){

    },
    onPageScroll: function(){

    },
    //item(index,pagePath,text)
    onTabItemTap:function(item){

    },

    // 获取用户信息
    async handlegetUserInfo() {
        try{
            // 获取用户信息
            const {rawData, signature, encryptedData, iv} = await getUserProfile();
            // 获取小程序登录成功后的code
            const {code} = await login();
            // 封装获取到的数据
            const loginParams = {rawData, signature, encryptedData, iv, code};
            // 发送请求获取用户的token（需要企业账号才能获取,此处自定义token用于模拟）
            // const {token} = await request({url:'/users/wxlogin', data:loginParams, method: 'POST'});
            const token = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo';
            wx.setStorageSync('token', token);
            wx.navigateBack({delta: 1});
        }catch(e){
            console.log(e);
        }
    }
});